export class ResponseFailResult {
	constructor(param) {
		const {
			errCode,
			errSubject,
			data,
			cause,
			errMsg
		} = param || {}
		this.errCode = errCode;
		this.errSubject = errSubject;
		this.data = data;
		this.cause = cause;
		this.errMsg = errMsg;
	}
}

// 定义下载响应参数类，用于封装下载响应
export class ResponseDownloadResult {
	constructor(param) {
		const {
			statusCode,
			tempFilePath,
			filePath
		} = param || {}
		this.statusCode = statusCode;
		this.tempFilePath = tempFilePath;
		this.filePath = filePath;
	}
}

// 定义响应参数类，用于封装请求返回数据
export class ResponseResult {
	constructor(param) {
		const {
			statusCode,
			header,
			data,
			cookies
		} = param || {}
		this.statusCode = statusCode;
		this.header = header;
		this.cookies = cookies;
		this.data = _handlerResponseResultData(data);
	}
}

function _handlerResponseResultData(data) {
	if (data) {
		if (typeof data === 'string') data = JSON.parse(data);
		if (typeof data === 'object') {
			data = new ResponseResultData(data);
		}
	}
	return data;
}

// 定义ResponseResultData类，用于封装响应数据
export class ResponseResultData {
	constructor(param) {
		const {
			code,
			msg,
			data
		} = param || {}
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
}

// 定义UploadOnProgressUpdateResult类，用于封装上传进度更新结果
export class UploadOnProgressUpdateResult {
	constructor(param) {
		// 解构赋值，从param中获取参数
		const {
			progress,
			totalBytesSent,
			totalBytesExpectedToSend
		} = param || {}
		// 将参数赋值给实例属性
		this.progress = progress;
		this.totalBytesSent = totalBytesSent;
		this.totalBytesExpectedToSend = totalBytesExpectedToSend;
	}
}

// 定义DownloadOnProgressUpdateResult类，用于封装下载进度更新结果
export class DownloadOnProgressUpdateResult {
	constructor(param) {
		const {
			progress,
			totalBytesWritten,
			totalBytesExpectedToWrite
		} = param || {}
		this.progress = progress;
		this.totalBytesWritten = totalBytesWritten;
		this.totalBytesExpectedToWrite = totalBytesExpectedToWrite;
	}
}